﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="utf-8" />
    <title>收件箱</title>
    <!--Jquery-->
    <script src="../../WF/Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>

    <!--bootstrap-->
    <link href="../../WF/Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />
    <link href="../../WF/Scripts/bootstrap/css/font-awesome.css" rel="Stylesheet" />
    <link  href="../../WF/Scripts/bootstrap/css/css.css" type="text/css"rel="stylesheet"  media="all" />
    <link href="../../WF/Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet" type="text/css" />
    <script src="../../WF/Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../../WF/Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js" type="text/javascript"></script>

    <!-- 引用基础js库. -->
    <script src="../../WF/Scripts/QueryString.js" type="text/javascript" ></script>
    <script src="../../WF/Scripts/QueryString2016.js" type="text/javascript" ></script>
    <script src="../../WF/Scripts/config.js?ver=1" type="text/javascript"></script>
    <script src="../../WF/Comm/Gener.js?ver=1" type="text/javascript"></script>
    <script src="../../WF/Comm/JScript.js?ver=1" type="text/javascript"></script>


    <!--模块化显示人员信息引入 JS-->
    <link href="../../WF/CCForm/JS/mselector.css" rel="stylesheet" type="text/css" />
    <script src="../../WF/CCForm/JS/mselector.js?ver=1" type="text/javascript"></script>
    <script src="../../WF/CCForm/JS/mtags.js?ver=1" type="text/javascript"></script>
    <script src="msgComm.js" type="text/javascript"></script>
    <script src="MsgDetail.js" type="text/javascript"></script>
    <style type="text/css">
     .nui-iput{
         width: 100%; 
        border-width: 0;
        background-color: transparent; 
        box-shadow: none;
        cursor: text;
        position: relative;
        padding: 9px 0 6px;
        zoom: 1;
    }
    </style>
    <script type="text/javascript">
        var pageIdx = 1;
        var firstLoadTable = false;
        $(function () {
            initBar();
            InitPage(pageIdx);
        });
        function InitPage(pageIndex) {
           if (pageIdx == null || pageIdx == "" || pageIndex == undefined)
             pageIdx = 1;
            //获取数据信息，解析成Table
           var pageCount = SearchData(pageIndex);

           pageCount = parseInt((pageCount) / 15) + 1;
            //分页设计
            Paginator(pageCount, pageIndex);
        }

        function SearchData(pageIndex) {
            if (pageIndex == null || pageIndex == undefined || pageIndex == "")
                pageIndex = 1;

            //初始化页面
            var inboxs = new Entities("BP.OA.Message.InBoxs");

            //获取收件箱总条数、未读条数
            var ht = inboxs.DoMethodReturnString("RetrieveCountData");
            if (ht.indexOf("err@") != -1) {
                alert(ht);
                return;
            }
            ht = JSON.parse(ht);
            if (ht.TotalCount == 0)
                $("#msgInfo").html("<span>你没有新的邮件</span>");
            else
                $("#msgInfo").html("<span>你有" + ht.TotalCount + "封邮件，有" + ht.UnReadCount + "封未读</span>");

            //获取分页的数据
            var searchKey = $("#TB_Key").val();
            var handler = new HttpHandler("BP.OA.HttpHandler.App_Message");
            handler.AddPara("PageIdx", pageIndex);
            handler.AddPara("SearchKey", searchKey);
            var data = handler.DoMethodReturnString("InitInBox");
            if (data.indexOf("err@") != -1) {
                alert(data);
                return;
            }
            data = JSON.parse(data);
            if (firstLoadTable)
                $('#dg').bootstrapTable("load",data);
            else
                bootstrapTableSet(data);
            return ht.TotalCount;
        }
        
        function bootstrapTableSet(data){
            //定义列明
            var columns = [{
                title: '',
                field: "_checkbox",
                align: 'center',
                width: 80,
                formatter: function (value, row, index) {
                    return "<input type='checkbox' id='" + row.MyPK + "' name='CB_InBox_" + row.InBoxState + "' />";
                }
            }, {
                title: '<img style="width: 15px; height: 12px;" src="img/Mail_Read.png">',
                field: "",
                align: 'center',
                width: 80,
                formatter: function (value, row, index) {
                    if (row.InBoxState == 0)
                        return "<img style='width: 15px; height: 12px;margin-top:4px;' src='img/Mail_UnRead.png'>";
                    //已读
                    else
                        return "<img style='width: 15px; height: 12px;margin-top:4px;' src='img/Mail_Read.png'>";
                }

            },{
                title: '<img style="height: 12px;" src="img/Attach.png">',
                field: "",
                align: 'center',
                width:80,
                formatter: function (value, row, index) {
                    return;
                }

            },{
                title: "发件人",
                field: "SenderName",
                width:240
            },{
                title: "标题",
                field: "Title"
            },{
                title: "发送时间",
                field: "SendTime",
                width:200
            }]
            
            $('#dg').bootstrapTable({
                data: data,
                columns: [columns],
                cache:false,
                striped: true,
                singleSelect: true,
                sidePagination: "server",
                pageNumber: 1,
                strictSearch: false,
                detailView:true,
                onExpandRow:function (index,row,$detail) {
                    initSubTable(index,row,$detail,1);
                }
            });

            firstLoadTable = true;
        }

    
        function selectInbox(obj) {
            if (obj.checked == false)
                obj.checked = true;
            else
                obj.checked = false; 
        }

        function changeCheckState(obj) {
            if (obj.checked == true)
                SelectAll();
            else
                UnSelectAll();
        }
        //全选
        function SelectAll() {
            var checkBoxs = $("input[type='checkbox']");
            $.each(checkBoxs, function (i, obj) {
                obj.checked = true;
            });
        }

        //全不选
        function UnSelectAll() {
            var checkBoxs = $("input[type='checkbox']");
            $.each(checkBoxs, function (i, obj) {
                obj.checked = false;
            });
        }

        //选中已读的
        function SelectRead() {
            var readChecks = $("input[name='CB_InBox_1']");
            $.each(readChecks, function (i, obj) {
                obj.checked = true;
            });

            var unReadChecks = $("input[name='CB_InBox_0']");
            $.each(unReadChecks, function (i, obj) {
                obj.checked = false;
            });

            
        }

        //选中未读的
        function SelectUnRead() {
            var readChecks = $("input[name='CB_InBox_1']");
            $.each(readChecks, function (i, obj) {
                obj.checked = false;
            });

            var unReadChecks = $("input[name='CB_InBox_0']");
            $.each(unReadChecks, function (i, obj) {
                obj.checked = true;
            });

        }

        //删除邮件
        function DeleteMsg() {
            var checkBoxs = $("input[type='checkbox']:checked");
            if (checkBoxs.length == 0) {
                alert('没有选中任何邮件，请选择');
                return;
            }
            if (confirm("你确定要删除邮件吗，删除邮件后进入垃圾箱中") == false)
                return;

            $.each(checkBoxs, function (i, obj) {
                if (obj.id == "selectAll")
                    return;
                var myPK = obj.id;
                var en = new Entity("BP.OA.Message.InBox", myPK);
                en.InBoxState = 2;
                en.Update();
            });
            InitPage(pageIdx);
        }

        //设置已读
        function SetMsgRead() {
            var checkBoxs = $("input[type='checkbox']:checked");
            if (checkBoxs.length == 0) {
                alert('没有选中任何邮件，请选择');
                return;
            }
            $.each(checkBoxs, function (i, obj) {
                if (obj.id == "selectAll")
                    return;
                var myPK = obj.id;
                var en = new Entity("BP.OA.Message.InBox", myPK);
                en.InBoxState = 1;
                en.Update();
            });
            InitPage(pageIdx);
        }

        //设置未读
        function SetMsgUnRead() {
            var checkBoxs = $("input[type='checkbox']:checked");
            if (checkBoxs.length == 0) {
                alert('没有选中任何邮件，请选择');
                return;
            }

            $.each(checkBoxs, function (i, obj) {
                if (obj.id == "selectAll")
                    return;
                var myPK = obj.id;
                var en = new Entity("BP.OA.Message.InBox", myPK);
                en.InBoxState = 0;
                en.Update();
            });
            InitPage(pageIdx);

        }

        //设置已读
        function SetAllMsgRead() {
            var ens = new Entities("BP.OA.Message.InBoxs");
            ens.DoMethodReturnString("SetMsgRead");
            InitPage(pageIdx);
        }

       

        function Paginator(pageCount,currentPage) {
            var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                shouldShowPage: true, //是否显示该按钮
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }, //点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    pageIdx = page;
                    SearchData(page);
                }
            };
            $('#useroption').bootstrapPaginator(options);
        }

        //刷新
        function Refreah() {
            InitPage(1);
        }

        function Search() {
            InitPage(pageIdx);
        }
    </script>
    <style type="text/css">
       .table > thead > tr > th, 
       .table > tbody > tr > td, 
       .table > tfoot > tr > td
       .table > tfoot > tr > th, 
       .table > thead > tr > td
       
        {
            border: 1px solid #ddd;
        }
        
        .table-striped > thead > tr:nth-of-type(odd)
        {
            background-color:#f9f9f9;
            border: 1px solid #ddd;
        }
         .table-striped > tbody > tr:nth-of-type(odd)
        {
            background-color:#fff;
        }
        .pagination > .active > a, 
        .pagination > .active > span
        {
           z-index:3;
           cursor:default;
           background-color:#fff;
           border-color:#ddd;
           color:#337ab7;
        } 
        .pagination > li > a, .pagination > li > span
        {
            color:#337ab7;
        } 
        a, a:link, a:visited
        {
            font-weight:normal
        }
    </style>
</head>
<body>
<div id="alls" style="">
     <div  id="toolBar" style="margin-left:30px"><br /></div>
    <div style="margin-left:30px;margin-top:10px">
        <div class="btn-group">
	        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
		        <input type="checkbox" id="selectAll" onclick="changeCheckState(this)"/> <span class="caret"></span>
	        </button>
	        <ul class="dropdown-menu" role="menu">
		        <li><a href="javaScript:void(0);" onclick="SelectAll()">全选</a></li>
		        <li><a href="javaScript:void(0);" onclick="UnSelectAll()">不选</a></li>
		        <li><a href="javaScript:void(0);" onclick="SelectRead()">已读</a></li>
                <li><a href="javaScript:void(0);" onclick="SelectUnRead()">未读</a></li>
	        </ul>
        </div>
        <div class="btn-group">
             <button type="button" class="btn btn-default " onclick="DeleteMsg()">删除</button>
        </div>
        <div class="btn-group">
	        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
		        标记为 <span class="caret"></span>
	        </button>
	        <ul class="dropdown-menu" role="menu">
		        <li><a href="javaScript:void(0);" onclick="SetMsgRead()">已读</a></li>
		        <li><a href="javaScript:void(0);" onclick="SetMsgUnRead()">未读</a></li>
		        <li><a href="javaScript:void(0);" onclick="SetAllMsgRead()">全部标记为已读</a></li>
	        </ul>
        </div>
        <div class="btn-group">
             <button type="button" class="btn btn-default " onclick="Refreah()">刷新</button>
        </div>
        <div class="btn-group" style="float:right;margin-right:3px">
            <div class="form-inline">
                 <div class="form-group">
		            <input type="text" placeholder="请输入关键词" id="TB_Key" name="TB_Key" class="form-control">
		         </div>
                  <button class="btn btn-success" type="button" onclick="javascript:Search();"><i class="fa fa-search"></i> 查询</button>
            </div>
        </div>
        <br />
    </div>
    <div  style="margin-left:30px;margin-right:3px">
        <!--记录邮件总条数，未读的邮件-->
        <div class="form-group" style="margin-top:5px" >
            <label class="col-sm-12" style="color:Red" id="msgInfo"></label>
        </div>
        <!--显示邮件信息-->
        <div><table id="dg" class="table table-hover" style="word-wrap: break-word; word-break: break-all;"></table></div>
         <div style="text-align:center;margin-top:-10px">
            <ul class="pagination" id="useroption"></ul>
        </div>

    </div>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <input type="hidden" id="InBox_PK" />
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					原信转发
				</h4>
			</div>
			<div class="modal-body">
				<label for="TB_Recevier">发件人：</label>
                <input  type="text"" id="TB_Recevier" name="TB_Recevier" class="form-control" />
                <span id="msg"></span>
			</div>
			<div class="modal-footer">
                <span style="margin-right: 260px;">提示：原信转发不能退回</span>
				<button type="button" class="btn btn-default" data-dismiss="modal" onclick="Send()">
                    发送
				</button>
				<button type="button" class="btn btn-primary" onclick="Close()">
					取消
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
</body>
</html>
